%[gradientMag]=calcGradientMag(img) - Computes the magnitude of image gradient
%This function returns the magnitude of image gradient by taking the difference
%of the pixel values in the x direction and then the y direction and squaring
%the results.  The difference computation is currently implemented using the diff
%function.  This produces an ambiguity because is the difference of img(x,y)-img(x+1,y)
% computed for the img(x,y) pixel or the img(x+1,y) value.  currently it is set for the
% img(x+1,y).  this is because the filter being used to compute the difference is of
%even length.  A solution to this would be to interpolate the differentiator to an 
%odd filter length.
%
%The formula for the computation is: sqrt(((img)dx)^2 + ((img)dy)^2)
%
%INPUT ARGUMENT
%img - A matrix
%
%OUTPUT ARGUMENT
%gradientMag - the magnitude of the gradient.
%
%Author: Paul Otto
function gradientMag=calcGradientMag(img)

d1=diff(img,1,1);
d2=diff(img,1,2);

gradientMag=zeros(size(img));
gradientMag(2:end,:)=d1.^2;
gradientMag(:,2:end)=gradientMag(:,2:end)+d2.^2;

gradientMag=gradientMag.^(.5);

